package com.qf.ex;

import com.qf.entity.Result;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一处理异常
 * @author YDW
 * projectName:project2202_3
 * time:2022/5/15 23:01
 * description:
 */
@RestControllerAdvice
public class MyHandelException {

    /*
    * 处理自定义异常
    * */
    @ExceptionHandler({
            CustomException.class
    })
    public Result handleCustomException(CustomException e){
        e.printStackTrace();
        return Result.error(e.getMessage());
    }

    /*
    * 处理认证失败，或者没有权限的异常
    * */
    @ExceptionHandler({
            UnauthorizedException.class
    })
    public  Result  handleUnauthorizedException(UnauthorizedException e){
        e.printStackTrace();
        return new Result(401,"权限不足");
    }

    /*
    * 处理其他异常
    * */
    @ExceptionHandler({
            Exception.class
    })
    public  Result  handleOtherException(Exception e){
        return Result.error("系统异常，请联系管理员");
    }
}
